<?php
namespace Admin\Controller;

class IntegralController extends CommonController{

    /*积分商品列表*/
    public function index(){

        $this->where = array();
        $this->where['type'] = '3';
        $this->where['delete_status'] = '1';
        I('get.keywords') && $this->where['goods_name'] = array('like','%'.I('get.keywords').'%');
        $this->order = 'create_time desc';
        parent::index('Goods'); 
    }

    /*添加积分商品*/
    public function save(){

        if(IS_POST){
            $data = I('post.info');
            $data['goods_pics'] = I('post.goods_pics');
            if(!D('Goods')->create($data)) $this->error(D('Goods')->getError());
            $data['goods_logo'] = $data['goods_pics'][0];
            $res = D('Goods')->saveData($data);
            $res === false ? $this->error('保存失败') : $this->success('保存成功',U('index'));
        }else{
            $formData = array();
            I('get.id') && $formData = D('Goods')->where(array('id'=>(int)I('get.id')))->find();
            $this->assign('formData',output_data($formData));
            $this->display();
        }
    }

    //删除商品
    public function dele(){

        $res = D('Goods')->delData(intval(I('request.id')));
        $res ? $this->success('删除成功') : $this->error('删除失败');
    }

      /*修改 上/下架 状态*/
    public function set_status(){

        $result = D('Goods')->where(array('id'=>intval(I('post.id'))))->save(array('status'=>I('post.status')));
        empty($result)?$this->error():$this->success();
    }

    //礼品订单
    public function gift_order(){

        $this->where = array();
        $this->where['status'] = I('get.type');
        $this->where['order_type'] = 3;
        I('get.keywords') && $this->where['goods_name'] = array('like','%'.I('get.keywords').'%');
        $this->order = 'create_time desc';
        parent::index('Order'); 
    }

	//订单详情
	public function order_info(){

		$info = D('Order')->where(array('id'=>I('get.id')))->find();
		$this->assign('info',$info);
		$this->display();
	}
	
    
    public function send_goods(){

        $this->assign('id',(int)I('post.id'));
        $this->display();
    }
	
    public function do_send_goods(){
        
		$data = I('post.info');
		$res = D('Order')->save($data);
		$res === false ? $this->error('发货失败') : $this->success('发货成功');
    }
}
?>